import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Logger;

public class Display implements Command {

	public ArrayList<Task> tasks;
	public AddParser addParser;
	public Storage storage;
	public History history;
	public Logger logger;
	private boolean isError = false;
	String data;
	String errorMessage;
	String output;

	private static final int BASEINDEX = 1;
	private static final String DESIRED_TASK = "%d. %s\n";
	private static final String INVALID_COMMAND = "Command is invalid\n";
	private static final String COMMAND_DISPLAY = "display";

	// messages for display
	private static final String DISPLAY_EMPTY_TASK_LIST = "There is no tasks recorded.\n";

	public Display(ArrayList<Task> tasks, Storage storage, History history,
			Logger logger) {
		this.tasks = tasks;
		this.addParser = new AddParser();
		this.storage = storage;
		this.history = history;
		this.logger = logger;
		errorMessage = "";
	}

	@Override
	public void acceptInput(String data) {
		// TODO Auto-generated method stub
		this.data = data;

	}

	@Override
	public void execute() {
		// TODO Auto-generated method stub
		String allTasks = DISPLAY_EMPTY_TASK_LIST;
		StringBuilder obtainAllTasks = new StringBuilder();

		data = data.trim();
		if (!data.equals(COMMAND_DISPLAY)) {
			output = INVALID_COMMAND;
			isError = true;
		}

		// if (tasks.isEmpty()) {
		// output = allTasks;
		// }
		for (Task task : tasks) {
			obtainAllTasks.append(String.format(DESIRED_TASK,
					tasks.indexOf(task) + BASEINDEX, task.getContent()));
		}
		allTasks = obtainAllTasks.toString();
		allTasks.trim();
		if (tasks.isEmpty()) {
			output = DISPLAY_EMPTY_TASK_LIST;
		} else {
			output = allTasks;
		}

	}

	@Override
	public String save() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String outputToUser() {
		// TODO Auto-generated method stub
		return output;
	}

	@Override
	public boolean isError() {
		// TODO Auto-generated method stub
		return isError;
	}

}
